package com.x.linx.fenfencard.model;

import java.security.PublicKey;
import java.util.HashMap;
import java.util.Map;

import org.androidannotations.annotations.EBean;
import org.androidannotations.annotations.RootContext;

import android.content.Context;
import android.util.Log;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.google.gson.Gson;
import com.x.linx.fenfencard.model.meta.GenerateErrorListener;
import com.x.linx.fenfencard.model.meta.GenerateResponseListener;
import com.x.linx.fenfencard.model.meta.IRequestCallback;
import com.x.linx.fenfencard.model.meta.ReturnSignIn;
import com.x.linx.utils.D;

@EBean
public class UserProxy {
	private static final String TAG = UserProxy.class.getSimpleName();
	
	private final String URL_LOGIN = Config.URL_BASE + "v1/Member/SignIn";
	private static final String PARAM_NAME_USERNAME = "Name";
	private static final String PARAM_NAME_PASSWORD = "Password";

	@RootContext
	Context context;

	// + function
	public void signin(final String username, final String password,
			final IRequestCallback callback) {
		String url = URL_LOGIN;
		D.d(TAG, "signin url = " + url);
		RequestQueue mQueue = Volley.newRequestQueue(context);
		StringRequest postRequest = new StringRequest(Request.Method.POST, url,
				new GenerateResponseListener(ReturnSignIn.class, callback),
				new GenerateErrorListener(callback)) {

			protected Map<String, String> getParams() {
				Map<String, String> params = new HashMap<String, String>();
				params.put(PARAM_NAME_USERNAME, username);
				params.put(PARAM_NAME_PASSWORD, password);
				return params;
			}
		};
		mQueue.add(postRequest);
	}
	// - function
}
